package ac.svn.accesscontrol.ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import ac.notification.event.NotificationEvent;
import ac.notification.manager.NotificationRegistrar;
import ac.svn.accesscontrol.manager.SVNInfoManager;
import ac.svn.accesscontrol.store.ISVNIdentifier;
import ac.svn.accesscontrol.store.SVNGroup;
import ac.svn.accesscontrol.store.SVNUser;

public class GroupDeletionListener implements ActionListener{

    private String FuserId = "", FgroupId="";
    public GroupDeletionListener(String AgroupId,String AuserId)
    {
	FgroupId = AgroupId;
	FuserId 	= AuserId;
    }
    @Override
    public void actionPerformed(ActionEvent e) {
	SVNInfoManager infManager = SVNInfoManager.getInfoManager();

	//Remove user from group.
	SVNGroup svnGroup = infManager.getGroup(FgroupId);
	svnGroup.getGroupMembers().remove(FuserId);
	infManager.updateGroup(svnGroup);

	//Remove Group from user.
	SVNUser svnUser = infManager.getSvnUser(FuserId);
	svnUser.getGroups().remove(FgroupId);
	infManager.updateUser(svnUser);

	//Generate a notification so all who reflect state of group show updates.
	NotificationEvent event = new NotificationEvent(ISVNIdentifier.N_UIM_GROUP_MEM_UPDATE);
	event.setPropertyValue(FuserId);
	NotificationRegistrar.dispatchNotification(event);
    }

}